package com.app.ui.activity.base;

import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;

import com.app.config.entity.ImageEntity;
import com.app.ui.activity.action.NormalActionBar;
import com.app.ui.popupview.OptionPhotoPopupView;
import com.app.utiles.photo.ImageSelectManager;

import java.util.List;

/**
 * 选择单张照片
 * Created by junfengwang on 2017/1/5.
 */

public class PhotoOptionActivity extends NormalActionBar {
    private OptionPhotoPopupView photoPopupMenuView;
    private View view;
    protected ImageSelectManager imageSelectManager;


    public void initSeteleView() {
        View view = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
        initSeteleView(view);
    }

    public void initSeteleView(View view) {
        this.view = view;
        imageSelectManager = new ImageSelectManager(this);
        photoPopupMenuView = new OptionPhotoPopupView(this);
        photoPopupMenuView.setOnPhotoListener(new PhotoListener());
    }


    public void showView() {
        photoPopupMenuView.showLocation(view, Gravity.BOTTOM);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        List<ImageEntity> iamges = null;
        if (imageSelectManager != null) {
            iamges = imageSelectManager.onActivityResult(requestCode, resultCode, data);
        }
        if (iamges != null) {
            getImage(iamges);
        }
    }

    protected void setTitle(String popText) {
        photoPopupMenuView.setTitleText(popText);
    }

    protected void getImage(List<ImageEntity> images) {

    }

    class PhotoListener implements OptionPhotoPopupView.OnPhotoListener {

        @Override
        public void onPhotoChoose() {
            PhotoOptionActivity.this.onPhotoChoose();
        }

        @Override
        public void onPhotoTake() {
            PhotoOptionActivity.this.onPhotoTake();
        }

        @Override
        public void onPhotoCancel() {
            PhotoOptionActivity.this.onPhotoCancel();
        }
    }

    public void onPhotoChoose() {
        imageSelectManager.getSingleCropConfig();
    }

    public void onPhotoTake() {
        imageSelectManager.getSinglePhotoCropConfig();
    }

    public void onPhotoCancel() {
    }


}
